package com.mew.lobby.handler.sys;

import com.mew.common.exception.ResponseCode;
import com.mew.common.rest.StringMessage;
import com.mew.common.rest.bo.MewSession;
import com.mew.common.rest.feedback.FeedbackRequestMessage;
import com.mew.lobby.annotation.LobbyHandler;
import com.mew.lobby.net.LobbyHandlerMapCmdType;
import com.mew.lobby.net.MewHandler;
import com.mew.lobby.provide.SysFeignService;
import com.zebra.remoting.protocol.ZebraCommand;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;

/**
 * 修改签名
 * @author dylin
 * @create 2021/3/30
 */
@Service
@Slf4j
@LobbyHandler(LobbyHandlerMapCmdType.FEEDBACK)
public class FeedbackHandler implements MewHandler<FeedbackRequestMessage> {
    @Autowired
    private SysFeignService sysFeignService;
    @Override
    public void handle(ZebraCommand<FeedbackRequestMessage> zebraCommand, MewSession session) {
        Byte type = zebraCommand.getRequest().getType();
        String msg = zebraCommand.getRequest().getMsg();
        //字符长度大于300
        if(msg.length() > 300){
            zebraCommand.sendFailureCode(ResponseCode.LengthToMAx.code());
            return;
        }
        if (StringUtils.isNotEmpty(msg)){
            sysFeignService.feedback(session.uid,type,msg);
        }
        zebraCommand.sendSuccessMsg();
    }
}
